﻿// /////////////////////////////////// 
//  
//  
//      WiseLink CCF2.0 
//     (c)Copyright 2001-2010 WiseLink Xiaojun (David) Chen 
//        Authored and Owned Xiaojun (David) Chen 
//        All Right Reserved
//  
// /////////////////////////////////// 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZIC20Contract.Service;
using System.ServiceModel;
using Infrastructure.Log;
using ZICModel.Fault;
using ZICModel.ZISMessage;
using ZICModel.Position;
using ZIC20Contract.DataType;
namespace ZIC20
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class ZICService : IZIC20
    {
        private ZISFaultHandler m_zisFaultHandler;
        private ZISGateWay m_zisGateway;
        private PositionHandler m_positionHandler;

        public ZICService()
        {
            m_zisFaultHandler = new ZISFaultHandler();
            m_zisGateway = new ZISGateWay();
            m_positionHandler = new PositionHandler();
        }

        public string HeartbeatCheck(string str)
        {
            CallLogger.LogMessage(typeof(ZICService),"hello");
            return string.Format("Response To: {0}", str);
        }

        public void ProcessFaultInZIS(int maxId)
        {
            m_zisFaultHandler.GetAllFault();
        }
        public void ProcessUrgentInZIS(DateTime lastQueryTime)
        {
            m_zisFaultHandler.GetUrgentByLastQueryTime(lastQueryTime);
        }


        public int SendGPRSMessage(string idc, GPRSMsgType gprsType, string msg)
        {
            return m_zisGateway.SendGPRSMessage(idc, ZISMsgType.GPRS, gprsType, msg);
        }

        public int SendPOIMessage(string idc, POINavigation msg)
        {
            return m_zisGateway.SendPOIMessage(idc, ZISMsgType.GPRS, GPRSMsgType.POIInfo, msg);
        }

        public int SendClearCodeMessage(string idc, ClearCodeType code)
        {
            return m_zisGateway.SendClearCodeMessage(idc, code);
        }
        
        public int SendSystemUpgradeMessage(string idc)
        {
            return m_zisGateway.SendSystemUpgradeMessage(idc);
        }

        public int SendVehicleBrandCodeMessage(string idc, VehicleBrandCode code)
        {
            return m_zisGateway.SendVehicleBrandCodeMessage(idc, code);
        }


        public GPSPositionInfo GetLastKnownPosition(string idc)
        {
            return m_positionHandler.GetLastKnownGoodPosition(idc);
        }


        public IEnumerable<GPSPositionInfo> GpsPositionTrace(string idc, DateTime startTime, DateTime endTime)
        {
            return m_positionHandler.GpsPositionTrace(idc, startTime, endTime);
        }


        public bool RegisterDevice(string idc)
        {
            throw new NotImplementedException();
        }

        public bool QueryFaultInfo(string code, VehicleBrandCode brand)
        {
            throw new NotImplementedException();
        }
    }
}
